#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
测试网站注册
1. 批量注册指定人数
"""

__author__ = 'Lei Chen'

from api.objects import *
import logging
import threading
from api import config, ApiManager
import os
from log import setup_logging
import time

try:
    import thread
except ImportError:
    import _thread as thread

DIR = os.path.split(os.path.realpath(__file__))[0]
configParser = config.ApiConfigParser()
apiManager = ApiManager(configParser)
web = Web(configParser)
setup_logging()


def reg(userName):
    start = time.perf_counter()
    web.send_sms(username=userName, auth=False)

    params = {'country': '86', 'userName': userName, 'password': '111111aa', 'checkCode': '6666',
              'regType': 'phone'}
    result = web.post('user/reg', params=params, auth=False)
    end = time.perf_counter()
    times = end - start
    logging.info('注册：{0} 响应状态：{1} 状态：{2} 耗时：{3} 返回结果：{4}'.format(userName, result.status_code, result.success, times,
                                                                 result.json))


def main():
    for i in range(20000000600, 20000000700):
        threading.Thread(target=reg, args=(i,),
                         name='LoopThread-{0}'.format(i)).start()


if __name__ == '__main__':
    main()
